package com.wxg.demo.ch01.day01;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class ArgsTest01 {

    // -l
    @Test
    public void should_set_true_if_arg_exist() {
        BooleanOption option = Args.parse(BooleanOption.class, "-l");
        Assertions.assertTrue(option.logging());
    }

    @Test
    public void should_set_false_if_arg_not_exist() {
        BooleanOption option = Args.parse(BooleanOption.class);
        Assertions.assertFalse(option.logging());
    }

    static record BooleanOption(@Option("l") boolean logging) {}

    // -p 8080
    @Test
    public void test_int_8080() {
        IntOption option = Args.parse(IntOption.class, "-p", "8080");
        Assertions.assertEquals(8080, option.port());
    }

    static record IntOption(@Option("p") int port) {}

    // -d /usr/logs
    @Test
    public void test_string() {
        StringOption option = Args.parse(StringOption.class, "-d", "/usr/logs");
        Assertions.assertEquals("/usr/logs", option.directory());
    }

    static record StringOption(@Option("d") String directory) {}

    // -l -p 8080 -d /usr/logs
    @Test
    public void should_example_1() {
        MultiOptions options = Args.parse(MultiOptions.class, "-l", "-p", "8080", "-d", "/usr/logs");
        Assertions.assertTrue(options.logging());
        Assertions.assertEquals(8080, options.port());
        Assertions.assertEquals("/usr/logs", options.directory());
    }

    static record MultiOptions(@Option("l") boolean logging, @Option("p") int port, @Option("d") String directory) {}


    // -g this is a list -d 1 2 -3 5
    @Test
    @Disabled
    public void should_example_2() {
        ListOptions options = Args.parse(ListOptions.class, "-g", "this", "is", "a", "list", "-d", "1", "2", "-3", "5");
        Assertions.assertEquals(new String[]{"this", "is", "a", "list"}, options.group());
        Assertions.assertEquals(new int[]{1, 2, -3, 5}, options.decimals());
    }

    static record ListOptions(@Option("g") String[] group, @Option("d") int[] decimals) {}
}

